<template>
	<cover-view class="tabbar" :style="{'padding-bottom': paddingBottomHeight + 'rpx'}">
		<cover-view class="tabbar-item" v-for="(item, index) in list" :key="index">
			<view v-if="index!==2" @click="tabbarChange(item.pagePath)" class="icon-name" :class="{'selected': current == index}">
				<view class="iconfont" :class="item.iconClass"></view>
				<cover-view class="item-name" v-if="item.text">{{item.text}}</cover-view>
			</view>

			<view v-else class=" icon-name home-page" @click="tabbarChange(item.pagePath)">
				<cover-view class="home-icon">
					<view class="iconfont" :class="item.iconClass"></view>
				</cover-view>
			</view>
		</cover-view>
	</cover-view>
</template>

<script>
	export default {
		props: {
			current: Number
		},
		data() {
			return {
				paddingBottomHeight: 0, //苹果X以上手机底部适配高度
				list: [{
						"pagePath": "/pages/task/index",
						"text": "任务",
						"iconClass": "icon-renwu"
					},
					{
						"pagePath": "/pages/event/index",
						"text": "事件",
						"iconClass": "icon-shijian2"
					},
					{
						"pagePath": "/pages/index/index",
						"text": "工作台",
						"iconClass": "icon-a-shouye1"
					},
					{
						"pagePath": "/pages/book/index",
						"text": "通讯录",
						"iconClass": "icon-tongxunlu"
					},
					{
						"pagePath": "/pages/search/index",
						"text": "综合查询",
						"iconClass": "icon-zonghechaxun"
					}
				]
			}
		},
		created() {
			let that = this;
			uni.getSystemInfo({
				success: function(res) {
					let model = ['X', 'XR', 'XS', '11', '12', '13', '14', '15'];
					model.forEach(item => {
						//适配iphoneX以上的底部，给tabbar一定高度的padding-bottom
						if (res.model.indexOf(item) != -1 && res.model.indexOf('iPhone') != -1) {
							that.paddingBottomHeight = 40;
						}
					})
				}
			});
		},
		methods: {
			tabbarChange(path) {
				uni.switchTab({
					url: path
				})
			}
		}

	}
</script>

<style lang="scss" scoped>
	* {
		margin: 0;
		padding: 0;
		box-sizing: border-box;
	}
	.tabbar {
		width: 100%;
		height: 100rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		display: flex;
		justify-content: space-around;
		align-items: center;
		background-color: #ffffff;
		z-index: 100;
		border-top-left-radius: 40rpx;
		border-top-right-radius: 40rpx;
		box-shadow: 0 0 10px rgba(2, 122, 255, 0.2);

		.tabbar-item {
			display: flex;
			align-items: center;
			justify-content: center;
			height: 100rpx;
			position: relative;
			width: 20%;

			//主页
			.home-page {
				position: fixed;
				bottom: 40rpx;
				border-radius: 50%;
				z-index: 100;
				width: 110rpx;
				height: 110rpx;
				background-color: #fff;
				padding: 10rpx;
				box-shadow: 0 -5px 10px rgba(2, 122, 255, 0.2);
				text-align: center;

				.home-icon {
					width: 90rpx;
					height: 90rpx;
					background-color: #027AFF;
					border-radius: 50%;
					display: flex;
					justify-content: center;
					align-items: center;
					color: #Fff;

					.iconfont {
						font-size: 40rpx;
					}
				}
			}

			.icon-name {
				display: flex;
				justify-content: center;
				align-items: center;
				flex-wrap: wrap;
				flex-direction: column;
			}
			//选中样式
			.selected {
				.iconfont {
					color: #027AFF;
				}
				.item-name {
					color: #027AFF;
				}
			}

			.iconfont {
				margin-bottom: 4rpx;
				font-size: 32rpx;
			}

			.item-name {
				font-size: 26rpx;
				color: #A3A3A3;
			}
		}
	}
</style>
